<template>
	<view style="height: 100vh;">
		<map
			id="map1"
			ref="map1"
			style="width: 100%; height: 100%;"
			:latitude="latitude"
			:longitude="longitude"
			:markers="covers"
			:circles="circles"
			:show-location="showloc"
			:scale='12'
			@markertap='markertap'
		></map>
	</view>
</template>

<script>
var EARTH_RADIUS = 6378.137; //地球半径

function rad(d) {
	return (d * Math.PI) / 180.0;
}
function getDistance(lng1, lat1, lng2, lat2) {
	var radLat1 = rad(lat1);
	var radLat2 = rad(lat2);
	var a = radLat1 - radLat2;
	var b = rad(lng1) - rad(lng2);
	var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
	s = s * EARTH_RADIUS;
	s = Math.round(s * 10000) / 10000;
	return s; //返回数值单位：公里
}

export default {
	data() {
		return {
			latitude: 39.909,
			longitude: 116.39742,
			covers: [
				{
					latitude: 39.9,
					longitude: 116.39,
					iconPath: '../../static/adress.png'
				}
			],
			showloc: true,
			circles: [],
			list:[]
		};
	},
	methods: {
		markertap(a){
			console.log(a.markerId)
			this.gopage('place/place?id='+a.markerId)
		}
	},
	onLoad() {},
	onShow(){
		this.list=JSON.parse(this.$localStorage.getItem('list'))
		let covers=[];
		this.list.forEach(item=>{
			covers.push({
				latitude: item.lat,
				longitude: item.lng,
				iconPath: '../../static/adress.png',
				id:item._id
			})
		})
		this.covers=covers
		
		
		let t = uni.createMapContext('map1', this);
		t.moveToLocation();
		let _that=this
		uni.getLocation({
		    type: 'wgs84',
		    success: function (ad) {
		        console.log('当前位置：',ad)
				t.getRegion({
					success(res) {
						console.log('获取成功', res);
						
						
						let arr=[]
						
						arr.push({
							latitude:ad.latitude,
							longitude: ad.longitude,
							color: '#FF0000DD',
							fillColor: '#7cb5ec88',
							radius: 6000,
							strokeWidth: 1
						})
						_that.circles=arr
					}
				})
		    
		    }
		});
		
	}
};
</script>
<style lang="stylus" >

</style>
